package com.airconditioner.sales.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.airconditioner.sales.R;
import com.airconditioner.sales.adapter.HomeListAdapter;
import com.airconditioner.sales.view.AutoScrollTextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：shuizi_wade on 2017/1/16 14:26
 * 邮箱：674618016@qq.com
 */
@ContentView(R.layout.activity_home)
public class HomeActivity extends BaseActivity {
    @ViewInject(R.id.tv_scroll)
    AutoScrollTextView tv_scroll;
    @ViewInject(R.id.recyclerview)
    RecyclerView recyclerview;
    private HomeListAdapter adapter;
    private List<String> names = new ArrayList<>();
    private List<Integer> reIds = new ArrayList<>();

    @Override
    public void init() {
        super.init();
        initViews();
        initData();
    }

    private void initViews() {
        title_iv_back.setVisibility(View.INVISIBLE);
        title_tv_title.setText(R.string.home_title);
        title_iv_right.setImageResource(R.mipmap.home_sign_out);
        tv_scroll.initScrollTextView(this.getWindowManager(),
                "欢迎使用远程点播!撒韩国阿斯蒂芬哈看啊上岛咖啡啊阿飞");
        tv_scroll.starScroll();
    }

    @Event({R.id.title_right})
    private void getEvent(View view) {
        switch (view.getId()) {
            case R.id.title_right:
                jumpActvity(PaySuccessActivity.class);
                break;
        }
    }

    private void initData() {
        names.add(getString(R.string.sort_central_air_conditioning));
        names.add(getString(R.string.sort_primary_air_system));
        names.add(getString(R.string.sort_water_purifier));
        names.add(getString(R.string.sort_purifier));
        names.add(getString(R.string.sort_sale));
        names.add(getString(R.string.sort_other));
        names.add(getString(R.string.sort_hanging_air_conditioning));

        reIds.add(R.mipmap.home_icon_kt);
        reIds.add(R.mipmap.home_icon_fxt);


        reIds.add(R.mipmap.home_icon_jsq);
        reIds.add(R.mipmap.home_icon_jhq);
        reIds.add(R.mipmap.home_icon_tm);
        reIds.add(R.mipmap.home_icon_qt);
        reIds.add(R.mipmap.home_icon_kt);
        adapter = new HomeListAdapter(context, names, reIds);
        GridLayoutManager mgr = new GridLayoutManager(context, 3);
        recyclerview.setLayoutManager(mgr);
        //设置适配器
        recyclerview.setAdapter(adapter);
        adapter.setOnItemClickListener(new HomeListAdapter.MyItemClickListener() {
            @Override
            public void onItemClick(View view, int postion) {
                startActivity(new Intent(HomeActivity.this, ProductCategoryActivity.class));
            }
        });
    }
}
